#!/bin/bash

# 根据最新代码构建新的镜像
docker build -t nsjava:v2 .

# 创建新的Deployment和Service
kubectl apply -f k8s-dev-v2.yaml
kubectl apply -f k8s-service-v2.yaml

# 逐步将流量从旧的版本转移到新的版本上
for i in {0..3}; do
  kubectl patch deployment nsjava -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
  sleep 10
done

# 删除旧的Deployment和Service
kubectl delete deployment nsjava
kubectl delete service nsjava
